
<!DOCTYPE html>

<html>
  
<!-- Mirrored from docs.sympy.org/latest/modules/combinatorics/prufer.html by HTTrack Website Copier/3.x [XR&CO'2014], Sat, 15 Jan 2022 03:26:06 GMT -->
<!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=utf-8" /><!-- /Added by HTTrack -->
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />

    <title>Prufer Sequences &#8212; SymPy 1.9 documentation</title>
    <link rel="stylesheet" type="text/css" href="../../_static/pygments.css" />
    <link rel="stylesheet" type="text/css" href="../../_static/default.css" />
    <link rel="stylesheet" type="text/css" href="../../_static/graphviz.css" />
    <link rel="stylesheet" type="text/css" href="../../_static/plot_directive.css" />
    <link rel="stylesheet" type="text/css" href="../../../../live.sympy.org/static/live-core.css" />
    <link rel="stylesheet" type="text/css" href="../../../../live.sympy.org/static/live-autocomplete.css" />
    <link rel="stylesheet" type="text/css" href="../../../../live.sympy.org/static/live-sphinx.css" />
    
    <script data-url_root="../../" id="documentation_options" src="../../_static/documentation_options.js"></script>
    <script src="../../_static/jquery.js"></script>
    <script src="../../_static/underscore.js"></script>
    <script src="../../_static/doctools.js"></script>
    <script src="../../../../live.sympy.org/static/utilities.js"></script>
    <script src="../../../../live.sympy.org/static/external/classy.js"></script>
    <script src="../../../../live.sympy.org/static/live-core.js"></script>
    <script src="../../../../live.sympy.org/static/live-autocomplete.js"></script>
    <script src="../../../../live.sympy.org/static/live-sphinx.js"></script>
    
    <link rel="shortcut icon" href="../../_static/sympy-notailtext-favicon.ico"/>
    <link href="prufer.html" rel="canonical" />
    
    <link rel="index" title="Index" href="../../genindex.html" />
    <link rel="search" title="Search" href="../../search.html" />
    <link rel="next" title="Subsets" href="subsets.html" />
    <link rel="prev" title="Polyhedron" href="polyhedron.html" /> 
  </head><body>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="subsets.html" title="Subsets"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="polyhedron.html" title="Polyhedron"
             accesskey="P">previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../index.html">SymPy 1.9 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../index.html" >SymPy Modules Reference</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="index.html" accesskey="U">Combinatorics</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="#">Prufer Sequences</a></li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <section id="module-sympy.combinatorics.prufer">
<span id="prufer-sequences"></span><span id="combinatorics-prufer"></span><h1>Prufer Sequences<a class="headerlink" href="#module-sympy.combinatorics.prufer" title="Permalink to this headline">¶</a></h1>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.combinatorics.prufer.Prufer">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.combinatorics.prufer.</span></span><span class="sig-name descname"><span class="pre">Prufer</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kw_args</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/combinatorics/prufer.py#L8-L431"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.combinatorics.prufer.Prufer" title="Permalink to this definition">¶</a></dt>
<dd><p>The Prufer correspondence is an algorithm that describes the
bijection between labeled trees and the Prufer code. A Prufer
code of a labeled tree is unique up to isomorphism and has
a length of n - 2.</p>
<p>Prufer sequences were first used by Heinz Prufer to give a
proof of Cayley’s formula.</p>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r76"><span class="brackets"><a class="fn-backref" href="#id1">R76</a></span></dt>
<dd><p><a class="reference external" href="http://mathworld.wolfram.com/LabeledTree.html">http://mathworld.wolfram.com/LabeledTree.html</a></p>
</dd>
</dl>
<dl class="py method">
<dt class="sig sig-object py" id="sympy.combinatorics.prufer.Prufer.edges">
<em class="property"><span class="pre">static</span> </em><span class="sig-name descname"><span class="pre">edges</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">runs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/combinatorics/prufer.py#L236-L289"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.combinatorics.prufer.Prufer.edges" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a list of edges and the number of nodes from the given runs
that connect nodes in an integer-labelled tree.</p>
<p>All node numbers will be shifted so that the minimum node is 0. It is
not a problem if edges are repeated in the runs; only unique edges are
returned. There is no assumption made about what the range of the node
labels should be, but all nodes from the smallest through the largest
must be present.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics.prufer</span> <span class="kn">import</span> <span class="n">Prufer</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Prufer</span><span class="o">.</span><span class="n">edges</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">],</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">])</span> <span class="c1"># a T</span>
<span class="go">([[0, 1], [1, 2], [1, 3], [3, 4]], 5)</span>
</pre></div>
</div>
<p>Duplicate edges are removed:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Prufer</span><span class="o">.</span><span class="n">edges</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">],</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">],</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">6</span><span class="p">])</span> <span class="c1"># a K</span>
<span class="go">([[0, 1], [1, 2], [1, 4], [2, 3], [4, 5], [4, 6]], 7)</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.combinatorics.prufer.Prufer.next">
<span class="sig-name descname"><span class="pre">next</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">delta</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">1</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/combinatorics/prufer.py#L387-L407"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.combinatorics.prufer.Prufer.next" title="Permalink to this definition">¶</a></dt>
<dd><p>Generates the Prufer sequence that is delta beyond the current one.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics.prufer</span> <span class="kn">import</span> <span class="n">Prufer</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span> <span class="o">=</span> <span class="n">Prufer</span><span class="p">([[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">3</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">b</span> <span class="o">=</span> <span class="n">a</span><span class="o">.</span><span class="n">next</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span> <span class="c1"># == a.next()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">b</span><span class="o">.</span><span class="n">tree_repr</span>
<span class="go">[[0, 2], [0, 1], [1, 3]]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">b</span><span class="o">.</span><span class="n">rank</span>
<span class="go">1</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.combinatorics.prufer.Prufer.prufer_rank" title="sympy.combinatorics.prufer.Prufer.prufer_rank"><code class="xref py py-obj docutils literal notranslate"><span class="pre">prufer_rank</span></code></a>, <a class="reference internal" href="#sympy.combinatorics.prufer.Prufer.rank" title="sympy.combinatorics.prufer.Prufer.rank"><code class="xref py py-obj docutils literal notranslate"><span class="pre">rank</span></code></a>, <a class="reference internal" href="#sympy.combinatorics.prufer.Prufer.prev" title="sympy.combinatorics.prufer.Prufer.prev"><code class="xref py py-obj docutils literal notranslate"><span class="pre">prev</span></code></a>, <a class="reference internal" href="#sympy.combinatorics.prufer.Prufer.size" title="sympy.combinatorics.prufer.Prufer.size"><code class="xref py py-obj docutils literal notranslate"><span class="pre">size</span></code></a></p>
</div>
</dd></dl>

<dl class="py property">
<dt class="sig sig-object py" id="sympy.combinatorics.prufer.Prufer.nodes">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">nodes</span></span><a class="headerlink" href="#sympy.combinatorics.prufer.Prufer.nodes" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the number of nodes in the tree.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics.prufer</span> <span class="kn">import</span> <span class="n">Prufer</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Prufer</span><span class="p">([[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">3</span><span class="p">],</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">3</span><span class="p">],</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">],</span> <span class="p">[</span><span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">],</span> <span class="p">[</span><span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">]])</span><span class="o">.</span><span class="n">nodes</span>
<span class="go">6</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Prufer</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">])</span><span class="o">.</span><span class="n">nodes</span>
<span class="go">5</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.combinatorics.prufer.Prufer.prev">
<span class="sig-name descname"><span class="pre">prev</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">delta</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">1</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/combinatorics/prufer.py#L409-L431"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.combinatorics.prufer.Prufer.prev" title="Permalink to this definition">¶</a></dt>
<dd><p>Generates the Prufer sequence that is -delta before the current one.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics.prufer</span> <span class="kn">import</span> <span class="n">Prufer</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span> <span class="o">=</span> <span class="n">Prufer</span><span class="p">([[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">],</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">],</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">4</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span><span class="o">.</span><span class="n">rank</span>
<span class="go">36</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">b</span> <span class="o">=</span> <span class="n">a</span><span class="o">.</span><span class="n">prev</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">b</span>
<span class="go">Prufer([1, 2, 0])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">b</span><span class="o">.</span><span class="n">rank</span>
<span class="go">35</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.combinatorics.prufer.Prufer.prufer_rank" title="sympy.combinatorics.prufer.Prufer.prufer_rank"><code class="xref py py-obj docutils literal notranslate"><span class="pre">prufer_rank</span></code></a>, <a class="reference internal" href="#sympy.combinatorics.prufer.Prufer.rank" title="sympy.combinatorics.prufer.Prufer.rank"><code class="xref py py-obj docutils literal notranslate"><span class="pre">rank</span></code></a>, <a class="reference internal" href="#sympy.combinatorics.prufer.Prufer.next" title="sympy.combinatorics.prufer.Prufer.next"><code class="xref py py-obj docutils literal notranslate"><span class="pre">next</span></code></a>, <a class="reference internal" href="#sympy.combinatorics.prufer.Prufer.size" title="sympy.combinatorics.prufer.Prufer.size"><code class="xref py py-obj docutils literal notranslate"><span class="pre">size</span></code></a></p>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.combinatorics.prufer.Prufer.prufer_rank">
<span class="sig-name descname"><span class="pre">prufer_rank</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/combinatorics/prufer.py#L291-L313"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.combinatorics.prufer.Prufer.prufer_rank" title="Permalink to this definition">¶</a></dt>
<dd><p>Computes the rank of a Prufer sequence.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics.prufer</span> <span class="kn">import</span> <span class="n">Prufer</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span> <span class="o">=</span> <span class="n">Prufer</span><span class="p">([[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">3</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span><span class="o">.</span><span class="n">prufer_rank</span><span class="p">()</span>
<span class="go">0</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.combinatorics.prufer.Prufer.rank" title="sympy.combinatorics.prufer.Prufer.rank"><code class="xref py py-obj docutils literal notranslate"><span class="pre">rank</span></code></a>, <a class="reference internal" href="#sympy.combinatorics.prufer.Prufer.next" title="sympy.combinatorics.prufer.Prufer.next"><code class="xref py py-obj docutils literal notranslate"><span class="pre">next</span></code></a>, <a class="reference internal" href="#sympy.combinatorics.prufer.Prufer.prev" title="sympy.combinatorics.prufer.Prufer.prev"><code class="xref py py-obj docutils literal notranslate"><span class="pre">prev</span></code></a>, <a class="reference internal" href="#sympy.combinatorics.prufer.Prufer.size" title="sympy.combinatorics.prufer.Prufer.size"><code class="xref py py-obj docutils literal notranslate"><span class="pre">size</span></code></a></p>
</div>
</dd></dl>

<dl class="py property">
<dt class="sig sig-object py" id="sympy.combinatorics.prufer.Prufer.prufer_repr">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">prufer_repr</span></span><a class="headerlink" href="#sympy.combinatorics.prufer.Prufer.prufer_repr" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns Prufer sequence for the Prufer object.</p>
<p>This sequence is found by removing the highest numbered vertex,
recording the node it was attached to, and continuing until only
two vertices remain. The Prufer sequence is the list of recorded nodes.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics.prufer</span> <span class="kn">import</span> <span class="n">Prufer</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Prufer</span><span class="p">([[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">3</span><span class="p">],</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">3</span><span class="p">],</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">],</span> <span class="p">[</span><span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">],</span> <span class="p">[</span><span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">]])</span><span class="o">.</span><span class="n">prufer_repr</span>
<span class="go">[3, 3, 3, 4]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Prufer</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">])</span><span class="o">.</span><span class="n">prufer_repr</span>
<span class="go">[1, 0, 0]</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.combinatorics.prufer.Prufer.to_prufer" title="sympy.combinatorics.prufer.Prufer.to_prufer"><code class="xref py py-obj docutils literal notranslate"><span class="pre">to_prufer</span></code></a></p>
</div>
</dd></dl>

<dl class="py property">
<dt class="sig sig-object py" id="sympy.combinatorics.prufer.Prufer.rank">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">rank</span></span><a class="headerlink" href="#sympy.combinatorics.prufer.Prufer.rank" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the rank of the Prufer sequence.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics.prufer</span> <span class="kn">import</span> <span class="n">Prufer</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">Prufer</span><span class="p">([[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">3</span><span class="p">],</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">3</span><span class="p">],</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">],</span> <span class="p">[</span><span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">],</span> <span class="p">[</span><span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="o">.</span><span class="n">rank</span>
<span class="go">778</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="o">.</span><span class="n">next</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span><span class="o">.</span><span class="n">rank</span>
<span class="go">779</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="o">.</span><span class="n">prev</span><span class="p">()</span><span class="o">.</span><span class="n">rank</span>
<span class="go">777</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.combinatorics.prufer.Prufer.prufer_rank" title="sympy.combinatorics.prufer.Prufer.prufer_rank"><code class="xref py py-obj docutils literal notranslate"><span class="pre">prufer_rank</span></code></a>, <a class="reference internal" href="#sympy.combinatorics.prufer.Prufer.next" title="sympy.combinatorics.prufer.Prufer.next"><code class="xref py py-obj docutils literal notranslate"><span class="pre">next</span></code></a>, <a class="reference internal" href="#sympy.combinatorics.prufer.Prufer.prev" title="sympy.combinatorics.prufer.Prufer.prev"><code class="xref py py-obj docutils literal notranslate"><span class="pre">prev</span></code></a>, <a class="reference internal" href="#sympy.combinatorics.prufer.Prufer.size" title="sympy.combinatorics.prufer.Prufer.size"><code class="xref py py-obj docutils literal notranslate"><span class="pre">size</span></code></a></p>
</div>
</dd></dl>

<dl class="py property">
<dt class="sig sig-object py" id="sympy.combinatorics.prufer.Prufer.size">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">size</span></span><a class="headerlink" href="#sympy.combinatorics.prufer.Prufer.size" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the number of possible trees of this Prufer object.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics.prufer</span> <span class="kn">import</span> <span class="n">Prufer</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Prufer</span><span class="p">([</span><span class="mi">0</span><span class="p">]</span><span class="o">*</span><span class="mi">4</span><span class="p">)</span><span class="o">.</span><span class="n">size</span> <span class="o">==</span> <span class="n">Prufer</span><span class="p">([</span><span class="mi">6</span><span class="p">]</span><span class="o">*</span><span class="mi">4</span><span class="p">)</span><span class="o">.</span><span class="n">size</span> <span class="o">==</span> <span class="mi">1296</span>
<span class="go">True</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.combinatorics.prufer.Prufer.prufer_rank" title="sympy.combinatorics.prufer.Prufer.prufer_rank"><code class="xref py py-obj docutils literal notranslate"><span class="pre">prufer_rank</span></code></a>, <a class="reference internal" href="#sympy.combinatorics.prufer.Prufer.rank" title="sympy.combinatorics.prufer.Prufer.rank"><code class="xref py py-obj docutils literal notranslate"><span class="pre">rank</span></code></a>, <a class="reference internal" href="#sympy.combinatorics.prufer.Prufer.next" title="sympy.combinatorics.prufer.Prufer.next"><code class="xref py py-obj docutils literal notranslate"><span class="pre">next</span></code></a>, <a class="reference internal" href="#sympy.combinatorics.prufer.Prufer.prev" title="sympy.combinatorics.prufer.Prufer.prev"><code class="xref py py-obj docutils literal notranslate"><span class="pre">prev</span></code></a></p>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.combinatorics.prufer.Prufer.to_prufer">
<em class="property"><span class="pre">static</span> </em><span class="sig-name descname"><span class="pre">to_prufer</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">tree</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">n</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/combinatorics/prufer.py#L140-L189"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.combinatorics.prufer.Prufer.to_prufer" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the Prufer sequence for a tree given as a list of edges where
<code class="docutils literal notranslate"><span class="pre">n</span></code> is the number of nodes in the tree.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics.prufer</span> <span class="kn">import</span> <span class="n">Prufer</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span> <span class="o">=</span> <span class="n">Prufer</span><span class="p">([[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">3</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span><span class="o">.</span><span class="n">prufer_repr</span>
<span class="go">[0, 0]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Prufer</span><span class="o">.</span><span class="n">to_prufer</span><span class="p">([[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">3</span><span class="p">]],</span> <span class="mi">4</span><span class="p">)</span>
<span class="go">[0, 0]</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<dl class="simple">
<dt><a class="reference internal" href="#sympy.combinatorics.prufer.Prufer.prufer_repr" title="sympy.combinatorics.prufer.Prufer.prufer_repr"><code class="xref py py-obj docutils literal notranslate"><span class="pre">prufer_repr</span></code></a></dt><dd><p>returns Prufer sequence of a Prufer object.</p>
</dd>
</dl>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.combinatorics.prufer.Prufer.to_tree">
<em class="property"><span class="pre">static</span> </em><span class="sig-name descname"><span class="pre">to_tree</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">prufer</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/combinatorics/prufer.py#L191-L234"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.combinatorics.prufer.Prufer.to_tree" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the tree (as a list of edges) of the given Prufer sequence.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics.prufer</span> <span class="kn">import</span> <span class="n">Prufer</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span> <span class="o">=</span> <span class="n">Prufer</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="mi">4</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span><span class="o">.</span><span class="n">tree_repr</span>
<span class="go">[[0, 1], [0, 2], [2, 3]]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Prufer</span><span class="o">.</span><span class="n">to_tree</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">])</span>
<span class="go">[[0, 1], [0, 2], [2, 3]]</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<dl class="simple">
<dt><a class="reference internal" href="#sympy.combinatorics.prufer.Prufer.tree_repr" title="sympy.combinatorics.prufer.Prufer.tree_repr"><code class="xref py py-obj docutils literal notranslate"><span class="pre">tree_repr</span></code></a></dt><dd><p>returns tree representation of a Prufer object.</p>
</dd>
</dl>
</div>
<p class="rubric">References</p>
<ul class="simple">
<li><p><a class="reference external" href="https://hamberg.no/erlend/posts/2010-11-06-prufer-sequence-compact-tree-representation.html">https://hamberg.no/erlend/posts/2010-11-06-prufer-sequence-compact-tree-representation.html</a></p></li>
</ul>
</dd></dl>

<dl class="py property">
<dt class="sig sig-object py" id="sympy.combinatorics.prufer.Prufer.tree_repr">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">tree_repr</span></span><a class="headerlink" href="#sympy.combinatorics.prufer.Prufer.tree_repr" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the tree representation of the Prufer object.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics.prufer</span> <span class="kn">import</span> <span class="n">Prufer</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Prufer</span><span class="p">([[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">3</span><span class="p">],</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">3</span><span class="p">],</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">],</span> <span class="p">[</span><span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">],</span> <span class="p">[</span><span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">]])</span><span class="o">.</span><span class="n">tree_repr</span>
<span class="go">[[0, 3], [1, 3], [2, 3], [3, 4], [4, 5]]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Prufer</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">])</span><span class="o">.</span><span class="n">tree_repr</span>
<span class="go">[[1, 2], [0, 1], [0, 3], [0, 4]]</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.combinatorics.prufer.Prufer.to_tree" title="sympy.combinatorics.prufer.Prufer.to_tree"><code class="xref py py-obj docutils literal notranslate"><span class="pre">to_tree</span></code></a></p>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.combinatorics.prufer.Prufer.unrank">
<em class="property"><span class="pre">classmethod</span> </em><span class="sig-name descname"><span class="pre">unrank</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">rank</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">n</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/combinatorics/prufer.py#L315-L332"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.combinatorics.prufer.Prufer.unrank" title="Permalink to this definition">¶</a></dt>
<dd><p>Finds the unranked Prufer sequence.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics.prufer</span> <span class="kn">import</span> <span class="n">Prufer</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Prufer</span><span class="o">.</span><span class="n">unrank</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">4</span><span class="p">)</span>
<span class="go">Prufer([0, 0])</span>
</pre></div>
</div>
</dd></dl>

</dd></dl>

</section>


            <div class="clearer"></div>
          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
            <p class="logo"><a href="../../index.html">
              <img class="logo" src="../../_static/sympylogo.png" alt="Logo"/>
            </a></p>
  <h4>Previous topic</h4>
  <p class="topless"><a href="polyhedron.html"
                        title="previous chapter">Polyhedron</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="subsets.html"
                        title="next chapter">Subsets</a></p>
  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="../../_sources/modules/combinatorics/prufer.rst.txt"
            rel="nofollow">Show Source</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <h3 id="searchlabel">Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="https://docs.sympy.org/latest/search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
      <input type="submit" value="Go" />
    </form>
    </div>
</div>
<script>$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="subsets.html" title="Subsets"
             >next</a> |</li>
        <li class="right" >
          <a href="polyhedron.html" title="Polyhedron"
             >previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../index.html">SymPy 1.9 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../index.html" >SymPy Modules Reference</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="index.html" >Combinatorics</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="#">Prufer Sequences</a></li> 
      </ul>
    </div>
    <div class="footer" role="contentinfo">
        &#169; Copyright 2021 SymPy Development Team.
      Last updated on Sep 30, 2021.
      Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 4.1.2.
    </div>
  </body>

<!-- Mirrored from docs.sympy.org/latest/modules/combinatorics/prufer.html by HTTrack Website Copier/3.x [XR&CO'2014], Sat, 15 Jan 2022 03:26:06 GMT -->
</html>